package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.TestItem;
import com.ruoyi.system.domain.TestPlan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TestCaseMapper;
import com.ruoyi.system.domain.TestCase;
import com.ruoyi.system.service.ITestCaseService;
import com.ruoyi.common.core.text.Convert;

/**
 * test_caseService业务层处理
 * 
 * @author ruoyi
 * @date 2022-09-27
 */
@Service
public class TestCaseServiceImpl implements ITestCaseService 
{
    @Autowired
    private TestCaseMapper testCaseMapper;

    /**
     * 查询test_case
     * 
     * @param caseId test_case主键
     * @return test_case
     */
    @Override
    public TestCase selectTestCaseByCaseId(Long caseId)
    {
        return testCaseMapper.selectTestCaseByCaseId(caseId);
    }

    /**
     * 查询test_case列表
     * 
     * @param testCase test_case
     * @return test_case
     */
    @Override
    public List<TestCase> selectTestCaseList(TestCase testCase)
    {
//        return testCaseMapper.selectTestCaseList(testCase);
        List<TestCase> testCaseList = testCaseMapper.selectTestCaseList(testCase);
        for (int i = 0; i < testCaseList.size(); i++) {
            Long testPlanId = testCaseList.get(i).getPlanId();
            TestPlan testPlan = testCaseMapper.selectTestPlanByPlanId(testPlanId);
            testCaseList.get(i).setPlanName(testPlan.getPlanName());
        }
        return testCaseList;
    }

    /**
     * 新增test_case
     * 
     * @param testCase test_case
     * @return 结果
     */
    @Override
    public int insertTestCase(TestCase testCase)
    {
        return testCaseMapper.insertTestCase(testCase);
    }

    /**
     * 修改test_case
     * 
     * @param testCase test_case
     * @return 结果
     */
    @Override
    public int updateTestCase(TestCase testCase)
    {
        return testCaseMapper.updateTestCase(testCase);
    }

    /**
     * 批量删除test_case
     * 
     * @param caseIds 需要删除的test_case主键
     * @return 结果
     */
    @Override
    public int deleteTestCaseByCaseIds(String caseIds)
    {
        return testCaseMapper.deleteTestCaseByCaseIds(Convert.toStrArray(caseIds));
    }

    /**
     * 删除test_case信息
     * 
     * @param caseId test_case主键
     * @return 结果
     */
    @Override
    public int deleteTestCaseByCaseId(Long caseId)
    {
        return testCaseMapper.deleteTestCaseByCaseId(caseId);
    }

    /**
     * 查询方法，这里可以到时候做数据验证，避免重复数据
     *
     */
    @Override
    public List<TestPlan> selectTestPlanName()
    {
        return testCaseMapper.selectTestPlanName();
    }

    /*@Override
    public int[] chart(Long sysUserId)
    {
        int[] stateNum = new int[3];

        for (int i = 0; i < 3; i++) {
            List<TestCase> testCaseList = testCaseMapper.chart(sysUserId, i);
            stateNum[i] = testCaseList.size();
        }

        return stateNum;
    }*/
}
